<?php 
// ----------------------------------------------------------
// * @Copyright @ 2011-2020 By HuaXiaXinCai
// ----------------------------------------------------------
// * @Author Yang Changwu<800334@qq.com> 2016-12-12
// ----------------------------------------------------------
error_reporting(0); //错误提示关闭
use \Workerman\Worker;
use \GatewayWorker\Lib\Db;
use \Controller\Redis;
use \Controller\Core;
use \Workerman\Lib\Timer;
use \Common\PHPMailer;
use \Workerman\Autoloader;


// 自动加载类
require_once __DIR__ . '/../../Workerman/Autoloader.php';
Autoloader::setRootPath(__DIR__);
// 写日志
Worker::$stdoutFile = '/tmp/stdout.log';
// bussinessWorker 进程
$worker = new Worker();
// worker名称
$worker->name = 'shaizhongServerClient';

$playrules = [
    1 => [
        'name' => '和值',
        'select' => [1, 2], //1单选 2复选 3全选 4复式
        'value' => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
        'award' => [
            4 => [112],
            5 => [113, 122],
            6 => [114, 123, 222],
            7 => [115, 124, 133, 223],
            8 => [116, 125, 134, 224, 233],
            9 => [126, 135, 144, 225, 234, 333],
            10 => [136, 145, 226, 235, 244, 334],
            11 => [146, 155, 236, 245, 335, 344],
            12 => [156, 246, 255, 336, 345, 444],
            13 => [166, 256, 346, 355, 445],
            14 => [266, 356, 446, 455],
            15 => [366, 456, 555],
            16 => [466, 556],
            17 => [566],
        ],
        'odds' => [40, 20, 12.5, 8, 6, 5, 4.5, 4.5, 5, 6, 8, 12.5, 20, 40], //单选,复选赔率一样
        'multiple' => 9999,
    ],
    2 => [
        'name' => '二同号',
        'select' => [1, 2],
        'value' => [112, 113, 114, 115, 116, 122, 223, 224, 225, 226, 133, 233, 334, 335, 336, 144, 244, 344, 445, 446, 155, 255, 355, 455, 556, 166, 266, 366, 466, 566],
        'award' => [
            11 => [112, 113, 114, 115, 116], 
            22 => [122,223, 224, 225, 226],
            33 => [133, 233,334, 335, 336],
            44 => [144, 244, 344,445, 446],
            55 => [155, 255, 355, 455,556],
            66 => [166, 266, 366, 466, 566],
        ],
        'odds' => [40, 7.5], //单选 40,复选 7.5
        'multiple' => 9999,
    ],
    3 => [
        'name' => '二不同号',
        'select' => [2],
        'value' => [12, 13, 14, 15, 16, 23, 24, 25, 26, 34, 35, 36, 45, 46, 56],
        'award' => [
            12 => [112,122,123,124,125,126],
            13 => [113,123,133,134,135,136],
            14 => [114,124,134,144,145,146],
            15 => [115,125,135,145,155,156],
            16 => [116,126,136,146,156,166],
            23 => [123,223,233,234,235,236],
            24 => [124,224,234,244,245,246],
            25 => [125,225,235,245,255,256],
            26 => [126,226,236,246,256,266],
            34 => [134,234,334,344,345,346],
            35 => [135,235,335,345,355,356],
            36 => [136,236,336,346,356,366],
            45 => [145,245,345,445,455,456],
            46 => [146,246,346,446,456,466],
            56 => [156,256,356,456,556,566],
        ],
        'odds' => [4], //复选 4
        'multiple' => 9999,
    ],
    4 => [
        'name' => '三同号',
        'select' => [1],
        'value' => [111, 222, 333, 444, 555, 666],
        'award' => [111, 222, 333, 444, 555, 666],
        'odds' => [120], //单选 120
        'multiple' => 9999,
    ],
    5 => [
        'name' => '三同号全选',
        'select' => [3],
        'value' => [111, 222, 333, 444, 555, 666],
        'award' => [111, 222, 333, 444, 555, 666],
        'odds' => [20], //全选 20
        'multiple' => 9999,
    ],
    6 => [
        'name' => '三不同号',
        'select' => [1,4],
        'value' => [123, 124, 125, 126, 134, 135, 136, 145, 146, 156, 234, 235, 236, 245, 246, 256, 345, 346, 356, 456],
        'award' => [123, 124, 125, 126, 134, 135, 136, 145, 146, 156, 234, 235, 236, 245, 246, 256, 345, 346, 356, 456],
        'odds' => [20], //单选 复式 20
        'multiple' => 9999,
    ],
    7 => [
        'name' => '三连号全选',
        'select' => [3],
        'value' => [123, 234, 345, 456],
        'award' => [123, 234, 345, 456],
        'odds' => [5], //全选 5
        'multiple' => 9999,
    ],
    8 => [
        'name' => '大',
        'select' => [1],
        'value' => [11, 12, 13, 14, 15, 16, 17, 18],
        'award' => [146, 155, 156, 166, 236, 245, 246, 255, 256, 266, 335, 336, 344, 345, 346, 355, 356, 366, 444, 445, 446, 455, 456, 466, 555, 556, 566, 666],
        'odds' => [2], //单选
        'multiple' => 9999,
    ],
    9 => [
        'name' => '小',
        'select' => [1],
        'value' => [3, 4, 5, 6, 7, 8, 9, 10],
        'award' => [111, 112, 113, 114, 115, 116, 122, 123, 124, 125, 126, 133, 134, 135, 136, 144, 145, 222, 223, 224, 225, 226, 233, 234, 235, 244, 333, 334],
        'odds' => [2], //单选
        'multiple' => 9999,
    ],
    10 => [
        'name' => '单',
        'select' => [1],
        'value' => [3, 5, 7, 9, 11, 13, 15, 17],
        'award' => [111, 113, 115, 122, 124, 126, 133, 135, 144, 146, 155, 166, 223, 225, 234, 236, 245, 256, 333, 335, 344, 346, 355, 366, 445, 456, 555, 566],
        'odds' => [2], //单选
        'multiple' => 9999,
    ],
    11 => [
        'name' => '双',
        'select' => [1],
        'value' => [4, 6, 8, 10, 12, 14, 16, 18],
        'award' => [112, 114, 116, 123, 125, 134, 136, 145, 156, 222, 224, 226, 233, 235, 244, 246, 255, 266, 334, 336, 345, 356, 444, 446, 455, 466, 556, 666],
        'odds' => [2], //单选
        'multiple' => 9999,
    ],
];

$worker->onWorkerStart = function($worker)
{
    //初始化mysql
    $db = Db::instance('db'); 
    //初始生成所有中奖号码
    $awardnumberall = Core::RankCombinAll();
    $awardnumberunique = Core::RankCombinUnique($awardnumberall);
//    $config = $db->select('*')->from('sz_config')->row();
//    $period = $db->select('*')->from('sz_period')->orderByASC(array('id'),false)->row();
//    $test = CalcAwardNubmer($db,$config,$period);
//    print_r($test);
    //定时执行期次开奖相关信息
    Timer::add(1, function()use($db,$awardnumberunique){
        periodrun($db,$awardnumberunique);
        EveryDayRun($db);
    });
    Timer::add(10, function()use($db,$awardnumberunique){
        //Monitor($db);
    });
};

function Monitor($db){
    $data['email']   = 'admin@19500.com';
    $data['toemail'] = 'flash165@qq.com';
    $data['subject'] = '中奖金额大于投注金额';
    $data['body']    = "<b>期次： 投注金额： 中奖金额：</b>";
    //发送到邮箱
    if(SendMail($data) == true){
        echo "发送邮箱成功\n";
    }else{
       echo "发送邮箱失败\n";
    }
}

function SendMail($data){
    $mail = new \Common\PHPMailer();
    $mail->IsSMTP(); // 使用SMTP方式发送
    $mail->CharSet='UTF-8';// 设置邮件的字符编码
    $mail->Host = 'smtp.163.com'; // 您的企业邮局服务器
    $mail->Port = 25; // 设置端口
    $mail->SMTPAuth = true; // 启用SMTP验证功能
    $mail->Username = 'cp588com@163.com'; // l邮局用户名(请填写完整的email地址)
    $mail->Password = "cp123321";
    $mail->From = 'cp588com@163.com'; //邮件发送者email地址
    $mail->FromName = "cp588";//
    $mail->AddAddress($data['toemail'], $data['uname']);//收件人地址，可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")

    $mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
    $mail->Subject = $data['subject'];//邮件标题'32wan游戏验证码'
    $mail->Body = $data['body']; //邮件内容"<b>您好！{$get['user']},您在87玩平台进行邮箱认证，验证码是：{$get['code']}</b>"
    //header("Content-type: text/html; charset=utf-8");
    if(!$mail->Send()){
            //发送失败
            return false;
    }else{
            //发送成功
            return true;
    }	
}

//每日23:59:59定时执行
function EveryDayRun($db){
    if(date('H:i:s',time()) == '23:59:59'){
        //增加每日用户在线时长日志
        $user = $db->select('username,dayline')->from('sz_user')->where('dayline > 0')->query();
        if($user){
            foreach ($user as $value) {
                $str .= "(NULL, '".$value['username'] ."', '".$value['dayline'] ."', '".strtotime(date('Y-m-d',time()) . ' 23:59:00') ."'),";
            }
            $sql = "INSERT INTO sz_onlinetime_log (`id`, `username`, `dateline`, `addtime`) VALUES ".substr($str,0,-1);
            $db->query($sql);
        }
        //设置每日在线时间为0 大转盘次数1
        $sqluser = "UPDATE sz_user SET dayline = 0,roulette=1";
        $db->query($sqluser);
    }
}

//期次执行
function periodrun($db,$awardnumberunique){
    //获取配置
    $config = $db->select('*')->from('sz_config')->row();
    //查询当前期次
    $period = $db->select('*')->from('sz_period')->orderByASC(array('id'),false)->row();

    if($period){
        //状态1已开奖,插入下一期
        if($period['status'] == 1){	
            if(substr($period['periodid'],0,8) == date('Ymd')){
                $peroid = (int)$period['periodid']+1;
            }else{
                $peroid = date('Ymd').'0001';
            }
            $period = [
                'periodid' => $peroid,
                'begintime' => time(),
                'endtime' => time()+$config['bettime']+$config['awardtime']+$config['exchangetime'],
                'bettime' => $config['bettime'],
                'awardtime' => $config['awardtime'],
                'exchangetime' => $config['exchangetime'],
                'awardnumber' => '',
                'odds' => $config['odds'],
                'betsum' => '0.00',
                'awardsum' => '0.00',
                'status' => 0,
            ];
            //写入期次
            $period['id']=$db->insert('sz_period')->cols($period)->query();
            //清除投注汇总
            $db->update('sz_betsum')->cols(array('periodid'=>$period['periodid'],'frequency'=>0,'betmoney'=>0.00,'awardmoney'=>0.00))->query();
        }
    }else{
        //不存在插入第一个期次
        $period = [
            'periodid'=> date('Ymd').'0001',
            'begintime'=> time(),
            'endtime'=> time()+$config['bettime']+$config['awardtime']+$config['exchangetime'],
            'bettime'=> $config['bettime'],
            'awardtime'=> $config['awardtime'],
            'exchangetime'=> $config['exchangetime'],
            'awardnumber' => '',
            'odds' => $config['odds'],
            'betsum' => '0.00',
            'awardsum' => '0.00',
            'status' =>0,
        ];
        //写入期次
        $period['id'] = $db->insert('sz_period')->cols($period)->query();
        //插入投注汇总
        foreach($awardnumberunique as $v){
                $str .= "(NULL, '".$period['periodid']."', '".$v."', '0',  '0.00', '0.00'),";
        }
        $sql = "INSERT INTO `sz_betsum` (`id`, `periodid`, `betnumber`, `frequency`, `betmoney`, `awardmoney`) VALUES ".substr($str,0,-1);
        $db->query($sql);
    }
    //下注倒记时
    $bettime = $period['endtime']-time()-$config['awardtime']-$config['exchangetime'];
    if($bettime>0){
        echo $period['periodid']."期下注时间:".$bettime."\n";
    }else{
        //开奖倒记时
        $awardtime = $period['endtime']-time()-$config['awardtime'];
        if($awardtime >0){
            //echo $period['periodid']."期开奖倒记间:".$awardtime."\n";
            if($awardtime == 9){
                if($period['awardnumber']){
                    $award_number = $period['awardnumber'];
                    //执行兑奖
                    ReturnAward($db,$period['periodid'], $award_number);
                }else{
                    //计算中奖号码
                    $award_number = CalcAwardNubmer($db,$config,$period);
                    //echo $period['periodid']."期开奖号码:".$award_number."\n";
                    //更新开奖号码
                    $db->update('sz_period')->cols(array('awardnumber'=>$award_number))->where("id=".$period['id'])->query();
                    //执行兑奖
                    ReturnAward($db,$period['periodid'], $award_number);
                }
                //更新期次状态
                $db->update('sz_period')->cols(array('status'=>2))->where("id=".$period['id'])->query();
            }
        }else{
            //兑奖倒记间
            $exchangetime = $period['endtime']-time();
            if($exchangetime >0){
                //echo $period['periodid']."兑奖倒记间:".$exchangetime."\n";
            }else{
                //更新期次状态
                $db->update('sz_period')->cols(array('status'=>1))->where("id=".$period['id'])->query();
            }
        }
    }
}
//计算返奖
function ReturnAward($db,$periodid,$awardnumber){
    $orderlist = $db->select('*')->from('sz_betorder')->where("periodid='$periodid' and awardstatus=0")->orderByASC(array('id'),false)->query();
    if($orderlist){
        $winmoney_sum = 0;
        foreach ($orderlist as $value){
            $winmoney = ExchangeAward($value['castcodes'],$awardnumber);
            $winmoney_sum +=$winmoney;
            if($winmoney == 0){
                $awardstatus = 1;
            }else{
                $awardstatus = 2;
            }
            //更新订单信息
            $sql = "UPDATE sz_betorder SET winmoney = $winmoney,awardstatus=$awardstatus,awardnumber ='$awardnumber'  WHERE orderid='".$value['orderid']."'";
            $db->query($sql);
            //更新用户金币
            $sql = "UPDATE sz_user SET gold =gold+$winmoney WHERE username='".$value['username']."'";
            $db->query($sql);
        }
        //减掉奖池金
        $sql = "UPDATE sz_config SET awardpool = awardpool-$winmoney_sum WHERE channel='3721zh'";
        $db->query($sql);
        //更新期次返金总额
        $db->update('sz_period')->cols(array('awardsum'=>$winmoney_sum))->where("periodid='$periodid'")->query();
        //echo $periodid."返奖总额:".$winmoney_sum."\n";
    }
}

//计算兑奖
function ExchangeAward($castcodes,$awardnumber) {
    global $playrules;
    $codes = explode(';', $castcodes);
    //中奖号码处理
    $awardnumber_val = explode(',', $awardnumber);
    sort($awardnumber_val);
    $awardnumber = implode('', $awardnumber_val);
    //中奖号码和值
    $awardnumber_sum = array_sum($awardnumber_val);
    //定义中奖金额
    $awardmoney = 0;
    foreach ($codes as $v) {
        $singlecodes = explode(':', $v);
        switch ($singlecodes[2]) {
            //和值
            case 1:
                $betcodes = explode(',', $singlecodes[0]);
                foreach ($betcodes as $value) {
                    $value = (int)$value;
                    if($value == $awardnumber_sum){
                        //赔率
                        $oddskey = array_search($value, $playrules[$singlecodes[2]]['value']);
                        $odds = $playrules[$singlecodes[2]]['odds'][$oddskey];

                        //计算中奖金额
                        //$awardmoney[1][1] += $singlecodes[3] * $odds;
                        $awardmoney += $singlecodes[3] * $odds;
                    }
                }
                break;
            //二同号
            case 2:
                $betcodes = explode(',', $singlecodes[0]);
                sort($betcodes);
                //单选 格式 1,6,1:1:2:10 号码161 单选类型 1  玩法二同号 2 倍数 10
                if ($singlecodes[1] == 1) {
                    //中奖号码
                    foreach ($betcodes as $v){
                        $v = (int)$v;
                        $award .= $v;
                    }                   
                    if ($award == $awardnumber) {
                        //赔率
                        $odds = $playrules[$singlecodes[2]]['odds'][0];

                        //计算中奖金额
                        //$awardmoney[2][1] += $singlecodes[3] * $odds;
                        $awardmoney += $singlecodes[3] * $odds;
                    }
                    unset($award);
                }
                //复选 11,22,33:2:2:10 号码11 22 33  复选类型 2  玩法二同号 2 倍数 10
                if ($singlecodes[1] == 2) {
                    foreach ($betcodes as $v){
                        $v = (int)$v;
                        //中奖号码
                        $award_array = $playrules[$singlecodes[2]]['award'][$v];

                        //判断值
                        if (in_array($awardnumber, $award_array)) {
                            //赔率
                            $odds = $playrules[$singlecodes[2]]['odds'][1];

                            //计算中奖金额
                            //$awardmoney[2][2] += $singlecodes[3] * $odds;
                            $awardmoney += $singlecodes[3] * $odds;
                        }
                    }
                }
                break;
            //二不同号
            case 3:
                //复选 格式 12,13,14:2:3:10 号码12 13 14 复选类型 2  玩法二不同号 3 倍数 10
                $betcodes = explode(',', $singlecodes[0]);
                foreach ($betcodes as $v){
                    $v = (int)$v;
                    //中奖号码
                    $award_array = $playrules[$singlecodes[2]]['award'][$v];

                    //判断值
                    if (in_array($awardnumber, $award_array)) {
                        //赔率
                        $odds = $playrules[$singlecodes[2]]['odds'][0];

                        //计算中奖金额
                        //$awardmoney[3][2] += $singlecodes[3] * $odds;
                        $awardmoney += $singlecodes[3] * $odds;
                    }
                }
                break;
            //三同号
            case 4:
                //单选 格式 1,1,1:1:4:10 号码111 单选类型 1  玩法三同号 3 倍数 10
                $betcodes = explode(',', $singlecodes[0]);
                foreach ($betcodes as $v){
                    $v = (int)$v; 
                    //中奖号码
                    $award .= $v;
                }
                if ($award == $awardnumber) {
                    //赔率
                    $odds = $playrules[$singlecodes[2]]['odds'][0];

                    //计算中奖金额
                    //$awardmoney[4][1] += $singlecodes[3] * $odds;
                    $awardmoney += $singlecodes[3] * $odds;
                }
                unset($award);
                break;
            //三同号全选
            case 5:
                //全选 格式 00:3:5:10 号码00 全选类型 3  玩法三同号全选 5 倍数 10
                //中奖号码
                $award_array = $playrules[$singlecodes[2]]['award'];

                //判断值
                if (in_array($awardnumber, $award_array)) {
                    //赔率
                    $odds = $playrules[$singlecodes[2]]['odds'][0];

                    //计算中奖金额
                    //$awardmoney[5][3] += $singlecodes[3] * $odds;
                    $awardmoney += $singlecodes[3] * $odds;
                }
                break;
            //三不同号
            case 6:
                $betcodes = explode(',', $singlecodes[0]);
                sort($betcodes);
                //单选 格式 1,2,3:1:6:10 号码1,2,3 单选类型 1  玩法三不同号 6 倍数 10
                if ($singlecodes[1] == 1) {
                    foreach ($betcodes as $v) {
                        $v = (int) $v;
                        //中奖号码
                        $award .= $v;
                    }
                    if ($award == $awardnumber) {
                        //赔率
                        $odds = $playrules[$singlecodes[2]]['odds'][0];

                        //计算中奖金额
                        //$awardmoney[6][1] += $singlecodes[3] * $odds;
                        $awardmoney += $singlecodes[3] * $odds;
                    }
                    unset($award);
                }
                //复式 格式 1,2,3,4:4:6:10 号码1,2,3,4 复式类型 4  玩法三不同号 6 倍数 10
                if ($singlecodes[1] == 4) {
                    //开奖号码
                    $betstr = [];
                    foreach ($betcodes as $v) {
                        $v = (int) $v;
                        array_push($betstr, $v);
                    }
                    $award_array = Core::RankCombin($betstr, 3,'');

                    //判断值
                    if (in_array($awardnumber, $award_array)) {
                        //赔率
                        $odds = $playrules[$singlecodes[2]]['odds'][0];

                        //计算中奖金额
                        //$awardmoney[6][2] += $singlecodes[3] * $odds;
                        $awardmoney += $singlecodes[3] * $odds;
                    }
                }
                break;
            //三连号全选
            case 7:
                //全选 格式 00:3:7:10 号码00 全选类型 3  玩法三连号全选 7 倍数 10
                //中奖号码
                $award_array = $playrules[$singlecodes[2]]['award'];

                //判断值
                if (in_array($awardnumber, $award_array)) {
                    //赔率
                    $odds = $playrules[$singlecodes[2]]['odds'][0];

                    //计算中奖金额
                    //$awardmoney[7][3] += $singlecodes[3] * $odds;
                    $awardmoney += $singlecodes[3] * $odds;
                }
                break;
            //大 格式 00:1:8:10 号码00所有 单选类型 1  玩法大 8 倍数 10
            case 8:
                //中奖号码
                $award_array = $playrules[$singlecodes[2]]['award'];

                //判断值
                if (in_array($awardnumber, $award_array)) {
                    //赔率
                    $odds = $playrules[$singlecodes[2]]['odds'][0];

                    //计算中奖金额
                    //$awardmoney[8][1] += $singlecodes[3] * $odds;
                    $awardmoney += $singlecodes[3] * $odds;
                }
                break;
            //小
            case 9:
                //中奖号码
                $award_array = $playrules[$singlecodes[2]]['award'];

                //判断值
                if (in_array($awardnumber, $award_array)) {
                    //赔率
                    $odds = $playrules[$singlecodes[2]]['odds'][0];

                    //计算中奖金额
                    //$awardmoney[9][1] += $singlecodes[3] * $odds;
                    $awardmoney += $singlecodes[3] * $odds;
                }
                break;
            //单
            case 10:
                //中奖号码
                $award_array = $playrules[$singlecodes[2]]['award'];

                //判断值
                if (in_array($awardnumber, $award_array)) {
                    //赔率
                    $odds = $playrules[$singlecodes[2]]['odds'][0];

                    //计算中奖金额
                    //$awardmoney[10][1] += $singlecodes[3] * $odds;
                    $awardmoney += $singlecodes[3] * $odds;
                }
                break;
            //双
            case 11:
                //中奖号码
                $award_array = $playrules[$singlecodes[2]]['award'];

                //判断值
                if (in_array($awardnumber, $award_array)) {
                    //赔率
                    $odds = $playrules[$singlecodes[2]]['odds'][0];

                    //计算中奖金额
                    //$awardmoney[11][1] += $singlecodes[3] * $odds;
                    $awardmoney += $singlecodes[3] * $odds;
                }
            break;
        }
    }
    return $awardmoney;
}

//计算中奖号码
function CalcAwardNubmer($db,$config,$period){
    //获取投注奖金
    $betsum = $db->select('*')->from('sz_betsum')->orderByASC(array('awardmoney'),false)->query();
    //获取投注总额
    $betmoney = $period['betsum'];
    echo "投注总额：".$betmoney."\n";
    //获取配置
    $odds = $period['odds']/100;
    echo "返奖比率：".$odds."\n";
    //计算返奖金额
    $awardmoney = $betmoney * $odds;
    echo "返奖金额：".$awardmoney ."\n";
    $awardnumber_list = [];
    //中奖号码按中奖金额为键名排列
    foreach ($betsum as $val){
        $awardnumber_list[$val['awardmoney']][] = $val;
    }
    file_put_contents(date('YmdH').'.txt', json_encode($awardnumber_list)."\t\n", FILE_APPEND);
    //中奖号码只有一个的时候,向下在取一组,随机产生中奖号码
    $awardnumber_list_temp = [];
    $not_awardnumber       = [];
    foreach ($awardnumber_list as $key => $value) {
        //奖池金-基础奖池金-(总充值金额*20%)-中奖金额
        $awardpool_temp = $config['awardpool'] - $config['basepool'] - ($config['paysum'] * 0.2) - $key;
        if($key < $awardmoney && $key > 0) {
            foreach ($value as $v){
                $awardnumber_list_temp[$v['betnumber']] = $v;
            }
            break;
        }
        //没计算出中奖号码,使用奖池赔得起的随机
        if(empty($awardnumber_list_temp)) {
            //奖池赔得起
            if($awardpool_temp >= 0) {
                array_push($not_awardnumber, $value);
            }
        }
    }

    //打乱中奖数组
    shuffle($awardnumber_list_temp);
    //print_r($not_awardnumber);
    //中奖号码列表不为空
    if (!empty($awardnumber_list_temp)) {
        $award_number = $awardnumber_list_temp[array_rand($awardnumber_list_temp, 1)];
    } elseif (!empty($not_awardnumber)) {
        foreach ($not_awardnumber as $value) {
            foreach ($value as $val) {
                $awardnumber_list_temp[$val['betnumber']] = $val;
            }
        }
        shuffle($awardnumber_list_temp);
        $award_number = $awardnumber_list_temp[array_rand($awardnumber_list_temp, 1)];
    } else {
        //中奖号码列表为空,所有号码随机
        $award_number = $betsum[array_rand($betsum, 1)];
    }
    //print_r($award_number);
    $awardnumber = substr($award_number['betnumber'],0,1).','.substr($award_number['betnumber'],1,1).','.substr($award_number['betnumber'],-1);
    $number = explode(',', $awardnumber);
    shuffle($number);
    $return = implode(',', $number);
    return $return;
}
function p($str){
    echo "==============================\n";
    echo $str."\n";
    echo "==============================\n";
}
function calctime(){
    /*计算时间开始*/
    $t1 = microtime(true);
    //执行程序
    
    $t2 = microtime(true);
    echo '耗时'.round($t2-$t1,3)."秒\n";
    /*计算时间结束*/
}
// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START')) {
    Worker::runAll();
}